package com.xoms.admin.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.xoms.admin.controller.res.BaseResult;
import com.xoms.admin.controller.res.ListResult;
import com.xoms.admin.controller.res.ObjectResult;
import com.xoms.admin.controller.res.bean.RProCategoryBean;
import com.xoms.admin.controller.res.bean.RProCategoryJSONBean;
import com.xoms.admin.controller.res.bean.RProJSONBean;
import com.xoms.admin.controller.res.bean.RProPriceBean;
import com.xoms.admin.controller.res.bean.RProSelectJSONBean;
import com.xoms.admin.controller.res.bean.RProStatusBean;
import com.xoms.admin.controller.res.bean.RProStatusLastTimeBean;
import com.xoms.admin.controller.res.bean.RProUnitBean;
import com.xoms.admin.controller.res.bean.RProductBean;
import com.xoms.admin.controller.res.bean.RProductDetailBean;
import com.xoms.admin.controller.springmvc.req.DelProCategoryParam;
import com.xoms.admin.controller.springmvc.req.DelProPriceParam;
import com.xoms.admin.controller.springmvc.req.DelProStatusParam;
import com.xoms.admin.controller.springmvc.req.DelProUnitParam;
import com.xoms.admin.controller.springmvc.req.DelProductParam;
import com.xoms.admin.controller.springmvc.req.DisableUnitParam;
import com.xoms.admin.controller.springmvc.req.EditProCategoryParam;
import com.xoms.admin.controller.springmvc.req.EditProPriceParam;
import com.xoms.admin.controller.springmvc.req.EditProStatusParam;
import com.xoms.admin.controller.springmvc.req.EditProUnitParam;
import com.xoms.admin.controller.springmvc.req.EditProductParam;
import com.xoms.admin.controller.springmvc.req.EditSorts2CategoryParam;
import com.xoms.admin.controller.springmvc.req.EditSorts2ProductParam;
import com.xoms.admin.controller.springmvc.req.EnableUnitParam;
import com.xoms.admin.controller.springmvc.req.GetCategorieParam;
import com.xoms.admin.controller.springmvc.req.GetProPricesParam;
import com.xoms.admin.controller.springmvc.req.GetProSaleStatusParam;
import com.xoms.admin.controller.springmvc.req.GetProStatusLastTimeParam;
import com.xoms.admin.controller.springmvc.req.GetProUnitsParam;
import com.xoms.admin.controller.springmvc.req.GetProductDetailParam;
import com.xoms.admin.controller.springmvc.req.GetProductParam;
import com.xoms.admin.controller.springmvc.req.GetProductsParam;
import com.xoms.admin.controller.springmvc.req.GetSelectProParam;
import com.xoms.admin.controller.springmvc.req.SaleProductParam;
import com.xoms.admin.controller.springmvc.req.SoldOutProductParam;
import com.xoms.admin.model.AccountBean;
import com.xoms.admin.service.ProCategoryService;
import com.xoms.admin.service.ProPriceService;
import com.xoms.admin.service.ProStatusService;
import com.xoms.admin.service.ProUnitService;
import com.xoms.admin.service.ProductService;
import com.xoms.admin.service.exception.ServiceException;
import com.xoms.admin.service.res.PageResult;
import com.xoms.util.NumUtil;
@Component
public class ProductController {

	@Autowired
	ProCategoryService proCategoryServiceImpl;

	@Autowired
	ProUnitService proUnitServiceImpl;
	
	@Autowired
	ProPriceService proPriceServiceImpl;
	
	@Autowired
	ProductService productServiceImpl;

	@Autowired
	ProStatusService proStatusServiceImpl;
	
	/**
	 * 根据商品分类
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ObjectResult<RProCategoryJSONBean> getAllCategories(HttpServletRequest request,
			HttpServletResponse response) {
		ObjectResult<RProCategoryJSONBean> result = new ObjectResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");
			// 获取全部商品分类列表
			RProCategoryJSONBean resData = proCategoryServiceImpl.getAllCategories(account);
			if (resData != null) {
				result.setData(resData);
			}
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}

	/**
	 * 编辑商品分类
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ObjectResult<RProCategoryBean> editCategory(EditProCategoryParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ObjectResult<RProCategoryBean> result = new ObjectResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号
			
			String cid = param.getCid();// 分类id
			String parentId = param.getParentId();
			String name = param.getName();
			
			//成功后返回编辑后分类信息
			RProCategoryBean data = proCategoryServiceImpl.edit(account, cid, name, parentId);
			result.setData(data);
			result.setFlag(data != null);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 删除商品分类
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public BaseResult delCategory(DelProCategoryParam param, HttpServletRequest request, HttpServletResponse response) {
		BaseResult result = new BaseResult();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号
			String cid =param.getCid();// 要删除的分类id

			boolean flag = proCategoryServiceImpl.del(account, cid);
			result.setFlag(flag);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 获取商品单位
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ListResult<RProUnitBean> getUnits(GetProUnitsParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ListResult<RProUnitBean> result = new ListResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");
			
			String key = param.getKey();// 关键字
			int page = NumUtil.toInt(param.getPage(), 0);
			int PageSize = NumUtil.toInt(param.getPageSize(), 20);
			// 获取部门列表
			PageResult<RProUnitBean> resData = proUnitServiceImpl.getUnits(account, key, page, PageSize);
			if (resData != null) {
				result.setData(resData.getData());
				result.setTotalSize(resData.getCount());
			}
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 编辑商品单位
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ObjectResult<RProUnitBean> editUnits(EditProUnitParam param, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RProUnitBean> result = new ObjectResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号

			int uid = NumUtil.toInt(param.getUid(), -1);// 为-1则新建
			String name = param.getName();// 单位名称
			String remark = param.getRemark();// 描述
			int isEnable = NumUtil.toInt(param.getIsEnable(), 1);// 默认启用
			
			//成功后返回编辑后部门信息
			RProUnitBean data = proUnitServiceImpl.edit(account, uid, name, remark, isEnable);
			result.setData(data);
			result.setFlag(data != null);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	

	/**
	 * 单位启用
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public BaseResult enableUnit(EnableUnitParam param, HttpServletRequest request, HttpServletResponse response) {
		BaseResult result = new BaseResult();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号
			int uid = NumUtil.toInt(param.getId(), -1);// 要启用的单位id

			boolean flag = proUnitServiceImpl.enable(account, uid);
			result.setFlag(flag);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 单位禁用
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public BaseResult disableUnit(DisableUnitParam param, HttpServletRequest request, HttpServletResponse response) {
		BaseResult result = new BaseResult();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号
			int uid = NumUtil.toInt(param.getId(), -1);// 要禁用的单位id

			boolean flag = proUnitServiceImpl.disable(account, uid);
			result.setFlag(flag);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 删除商品单位
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public BaseResult delUnit(DelProUnitParam param, HttpServletRequest request, HttpServletResponse response) {
		BaseResult result = new BaseResult();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号
			int uid = NumUtil.toInt(param.getUid(), -1);// 要删除的单位id

			boolean flag = proUnitServiceImpl.del(account, uid);
			result.setFlag(flag);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 商品列表
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ListResult<RProductBean> getProducts(GetProductsParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ListResult<RProductBean> result = new ListResult<>();

		try {
			AccountBean account = (AccountBean) request.getAttribute("account");
			String key = param.getKey();// 关键字
			String cid= param.getCid();//分类id
			String type = param.getType();// 总部一级分类id
			int page = NumUtil.toInt(param.getPage(), 0);
			int PageSize = NumUtil.toInt(param.getPageSize(), 20);
			// 获取商品列表
			PageResult<RProductBean> resData = productServiceImpl.getProducts(account, key, page,
					PageSize, cid, type);
			if (resData != null) {
				result.setData(resData.getData());
				result.setTotalSize(resData.getCount());
			}
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 获取商品价格
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ListResult<RProPriceBean> getPrices(GetProPricesParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ListResult<RProPriceBean> result = new ListResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");
			
			String key = param.getKey();// 关键字
			int page = NumUtil.toInt(param.getPage(), 0);
			int PageSize = NumUtil.toInt(param.getPageSize(), 20);
			String productId = param.getProductId();// 商品id
			// 获取商品价格列表
			PageResult<RProPriceBean> resData = proPriceServiceImpl.getPrices(account, key, productId, page, PageSize);
			if (resData != null) {
				result.setData(resData.getData());
				result.setTotalSize(resData.getCount());
			}
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 编辑商品价格
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ObjectResult<RProPriceBean> editPrice(EditProPriceParam param, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RProPriceBean> result = new ObjectResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号

			String pid = param.getPid();// 为空则新建
			String productId = param.getProductId();// 价格id
			Double price = NumUtil.toDouble(param.getPrice(), 0d);// 价格
			String remark = param.getRemark();// 描述
			String startTime = param.getStartTime();// 生效时间
			String endTime = param.getEndTime();// 终止时间
			int isEnable = NumUtil.toInt(param.getIsEnable(), 1);// 默认启用
			
			//成功后返回编辑后商品价格信息
			RProPriceBean data = proPriceServiceImpl.edit(account, pid, price, productId, remark, startTime, endTime, isEnable);
			result.setData(data);
			result.setFlag(data != null);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 删除商品价格
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public BaseResult delPrice(DelProPriceParam param, HttpServletRequest request, HttpServletResponse response) {
		BaseResult result = new BaseResult();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号
			String pid = param.getPid();// 商品价格id
			boolean flag = proPriceServiceImpl.del(account, pid);// 删除价格信息
			result.setFlag(flag);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 启用价格
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public BaseResult enablePrice(EnableUnitParam param, HttpServletRequest request, HttpServletResponse response) {
		BaseResult result = new BaseResult();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号
			String pid = param.getId();// 商品价格id
			
			boolean flag = proPriceServiceImpl.enable(account, pid);// 启用价格
			result.setFlag(flag);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 禁用价格
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public BaseResult disablePrice(DisableUnitParam param, HttpServletRequest request, HttpServletResponse response) {
		BaseResult result = new BaseResult();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号
			String pid = param.getId();// 商品价格id
			
			boolean flag = proPriceServiceImpl.disable(account, pid);// 禁用价格
			result.setFlag(flag);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 获取分类列表
	 * @param param 
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ObjectResult<RProCategoryJSONBean> getCategories(GetCategorieParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ObjectResult<RProCategoryJSONBean> result = new ObjectResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号
			
			int type = NumUtil.toInt(param.getType(), 0);// 0为全部查询
			// 返回三级分类列表
			RProCategoryJSONBean data = proCategoryServiceImpl.getCategories(account, type);
			result.setData(data);
			result.setFlag(data != null);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 新建编辑商品
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ObjectResult<RProductDetailBean> editProduct(EditProductParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ObjectResult<RProductDetailBean> result = new ObjectResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号
			
			String pid = param.getPid();// 为空则新建
			String name = param.getName();// 商品名称
			String productBar = param.getProductBar();
			String categroyArr = param.getCategoryArr();
			String imgUrl = param.getImgUrl();
			String specs = param.getSpecs();
			int unitId = NumUtil.toInt(param.getUnitId(), 0);
			String status = param.getStatus();
			int warnNum = NumUtil.toInt(param.getWarnNum(), 0);
			int maxNum = NumUtil.toInt(param.getMaxNum(), 0);
			int costType = NumUtil.toInt(param.getCostType(), 0);//
			String remark = param.getRemark();
			String groups = param.getGroups();
			double anitPrice = NumUtil.toDouble(param.getAntiPrice(), 0);
			int type = NumUtil.toInt(param.getType(), 0);// 总部一级分类
			
			//成功后返回编辑后商品信息
			RProductDetailBean data = productServiceImpl.edit(account, pid, name, productBar, categroyArr, imgUrl,
					specs, unitId, status, warnNum, remark, type, maxNum, costType, groups, anitPrice);
			result.setData(data);
			result.setFlag(data != null);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 获取商品详情信息
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ObjectResult<RProductDetailBean> getDetail(GetProductDetailParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ObjectResult<RProductDetailBean> result = new ObjectResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");
			// 根据id获取商品信息
			String productId = param.getPid();
			RProductDetailBean resData = productServiceImpl.getDetail2Pid(account, productId);
			if (resData != null) {
				result.setData(resData);
			}
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 搜索名称或条形码获取商品信息
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ListResult<RProductBean> getProduct(GetProductParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ListResult<RProductBean> result = new ListResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");
			String name = param.getName();
			String productBar = param.getProductBar();
			// 根据名称或条形码获取商品列表
			PageResult<RProductBean> resData = productServiceImpl.getProduct2NameBar(account, name, productBar);
			if (resData != null) {
				result.setData(resData.getData());
				result.setTotalSize(resData.getCount());
			}
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 获取一级分类列表
	 * @param request
	 * @param response
	 * @return
	 */
	public ObjectResult<RProCategoryJSONBean> getFirstCategories(HttpServletRequest request,
			HttpServletResponse response) {
		ObjectResult<RProCategoryJSONBean> result = new ObjectResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");
			// 获取总部一级商品分类列表
			RProCategoryJSONBean resData = proCategoryServiceImpl.getFirstCategories(account);
			if (resData != null) {
				result.setData(resData);
			}
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 获取商品售卖状态
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ListResult<RProStatusBean> getSaleStatus(GetProSaleStatusParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ListResult<RProStatusBean> result = new ListResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");
			
			int page = NumUtil.toInt(param.getPage(), 0);
			int PageSize = NumUtil.toInt(param.getPageSize(), 20);
			String productId = param.getProductId();// 商品id
			// 获取售卖状态列表
			PageResult<RProStatusBean> resData = proStatusServiceImpl.getStatuslist(account, productId, page, PageSize);
			if (resData != null) {
				result.setData(resData.getData());
				result.setTotalSize(resData.getCount());
			}
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 编辑新建商品售卖状态信息
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ObjectResult<RProStatusBean> editStatus(EditProStatusParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ObjectResult<RProStatusBean> result = new ObjectResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号

			String sid = param.getSid();// 为空则新建
			String productId = param.getProductId();// 价格id
			String status = param.getStatus();
			String remark = param.getRemark();// 描述
			String startTime = param.getStartTime();// 生效时间
			String endTime = param.getEndTime();// 结束时间
			
			//成功后返回编辑后商品售卖状态信息
			RProStatusBean data = proStatusServiceImpl.edit(account, sid, productId, status, remark, startTime, endTime);
			result.setData(data);
			result.setFlag(data != null);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 删除售卖状态信息
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public BaseResult delProStatus(DelProStatusParam param, HttpServletRequest request, HttpServletResponse response) {
		BaseResult result = new BaseResult();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号
			String sid = param.getSid();// 商品售卖状态id
			boolean flag = proStatusServiceImpl.del(account, sid);// 删除售卖状态信息
			result.setFlag(flag);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 上架
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public BaseResult proSale(SaleProductParam param, HttpServletRequest request, HttpServletResponse response) {
		BaseResult result = new BaseResult();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号
			String sid = param.getSid();// 商品状态id
			
			boolean flag = proStatusServiceImpl.onSale(account, sid);// 上架
			result.setFlag(flag);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 下架
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public BaseResult proSoldOut(SoldOutProductParam param, HttpServletRequest request, HttpServletResponse response) {
		BaseResult result = new BaseResult();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号
			String sid = param.getSid();// 商品状态id
			
			boolean flag = proStatusServiceImpl.soldOut(account, sid);// 下架
			result.setFlag(flag);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
		
	/**
	 * 获取最后失效时间
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ObjectResult<RProStatusLastTimeBean> getLastEndTime(GetProStatusLastTimeParam param,
			HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RProStatusLastTimeBean> result = new ObjectResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号

			String productId = param.getProductId();// 价格id
			
			//成功后返回编辑后商品售卖状态信息
			RProStatusLastTimeBean data = proStatusServiceImpl.getLastEndTime(account, productId);
			result.setData(data);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 获取商品排序列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	public ObjectResult<RProJSONBean> getSellList(HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RProJSONBean> result = new ObjectResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");
			// 获取全部商品分类列表
			RProJSONBean resData = productServiceImpl.getSellList(account);
			if (resData != null) {
				result.setData(resData);
			}
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 商品排序
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public BaseResult editSorts2Product(EditSorts2ProductParam param, HttpServletRequest request,
			HttpServletResponse response) {
		BaseResult result = new BaseResult();
		try {
			String sorts = param.getSorts();
			result.setFlag(productServiceImpl.editSorts2Product(sorts));
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 获取选择下拉商品
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public ObjectResult<RProSelectJSONBean> getSelectList(GetSelectProParam param, HttpServletRequest request,
			HttpServletResponse response) {
		ObjectResult<RProSelectJSONBean> result = new ObjectResult<>();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");
			int type = NumUtil.toInt(param.getType(), 1);
			// 获取选择商品列表
			RProSelectJSONBean resData = productServiceImpl.getSelectList(account, type);
			if (resData != null) {
				result.setData(resData);
			}
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
		
	}
	
	/**
	 * 删除商品
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public BaseResult delProduct(DelProductParam param, HttpServletRequest request, HttpServletResponse response) {
		BaseResult result = new BaseResult();
		try {
			AccountBean account = (AccountBean) request.getAttribute("account");// 登录账号
			String pid = param.getPid();// 删除商品id

			boolean flag = productServiceImpl.delProduct(account, pid);
			result.setFlag(flag);
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}
	
	/**
	 * 商品分类排序
	 * @param param
	 * @param request
	 * @param response
	 * @return
	 */
	public BaseResult editSorts2Category(EditSorts2CategoryParam param, HttpServletRequest request,
			HttpServletResponse response) {
		BaseResult result = new BaseResult();
		try {
			String sorts = param.getSorts();
			result.setFlag(proCategoryServiceImpl.editSorts2Category(sorts));
		} catch (ServiceException e) {
			result.setServiceException(e);
		}
		return result;
	}

}
